
package com.ruoyi.web.controller.lingshui.enterprise;


import java.util.List;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.LSBusinessException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.supervise.domain.BaseBulidUnitInfo;
import com.ruoyi.supervise.domain.BaseCorpCertInfo;
import com.ruoyi.supervise.domain.BaseUnitInfo;
import com.ruoyi.supervise.domain.Enterprise;
import com.ruoyi.supervise.domain.EnterpriseTable;
import com.ruoyi.supervise.domain.IGMCompanyCreditRank;
import com.ruoyi.supervise.domain.IGMCompanyPoorInfo;
import com.ruoyi.supervise.domain.IGMCompanyWellInfo;
import com.ruoyi.supervise.domain.IntegrityPerformance;
import com.ruoyi.supervise.domain.MyTest;
import com.ruoyi.supervise.domain.PersonInfo;
import com.ruoyi.supervise.service.IBaseUnitInfoService;
import com.ruoyi.supervise.service.IEnterpriseService;
import com.ruoyi.supervise.service.IMyTestService;
import com.ruoyi.supervise.service.IPersonInfoService;

/**
 * @ClassName: EnterpriseController
 * @Description: 企业controller
 * @Author wtj
 * @DateTime 2020年3月19日 上午10:08:07
 */
@Controller
@RequestMapping("/enterprise/enterprise")
public class EnterpriseController extends BaseController{

	private String prefix = "lingshui/enterprise";
	
	@Autowired
    private IEnterpriseService enterpriseService;
	
	@Autowired
	private IPersonInfoService personInfoService;
	
	@Autowired
	private IBaseUnitInfoService baseUnitInfoService;
	
	@Autowired
	private IMyTestService myTestService;
	
	/**
	 * @Title: enterprise
	 * @Description: 跳转到企业档案库页面
	 * @Author wtj
	 * @DateTime 2020-9-27 15:53:25
	 * @return
	 */
	@RequiresPermissions("enterprise:enterpriseAll:view")
	@GetMapping()
	public String enterprise()
	{
	    return prefix + "/enterprise";
	}
	
	/**
	 * @Title: list
	 * @Description: 查询出企业档案库table数据
	 * @Author wtj
	 * @DateTime 2020年3月24日 上午11:57:24
	 * @param enterpriseTable
	 * @return
	 */
    @RequiresPermissions("enterprise:enterpriseAll:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EnterpriseTable enterpriseTable,ModelMap mmap)
    {
        startPage();
        List<EnterpriseTable> enterpriseTableList=enterpriseService.selectEnterpriseTableList(enterpriseTable);
        for(EnterpriseTable et:enterpriseTableList) {
        	if(et != null) {
        		if(!StringUtils.isEmpty(et.getRegProvinceNum()) && !StringUtils.isEmpty(et.getRegCityNum())) {
        			et.setRegProvinceCity(et.getRegProvinceNum()+et.getRegCityNum());
        		}else if(!StringUtils.isEmpty(et.getRegProvinceNum()) && StringUtils.isEmpty(et.getRegCityNum())) {
        			et.setRegProvinceCity(et.getRegProvinceNum());
        		}else if(StringUtils.isEmpty(et.getRegProvinceNum()) && !StringUtils.isEmpty(et.getRegCityNum())) {
        			et.setRegProvinceCity(et.getRegCityNum());
        		}else {
        			et.setRegProvinceCity(" ");
        		}
        	}
        }
        return getDataTable(enterpriseTableList);
    }
    
   /**
    * @Title: detail
    * @Description: 企业详情
    * @Author wtj
    * @DateTime 2020年4月23日 下午2:23:27
    * @param guid
    * @param mmap
    * @return
    */
   @RequiresPermissions(value={"enterprise:enterpriseAll:basicinfo", "enterprise:enterpriseAll:qua", "enterprise:enterpriseAll:cxpj", "enterprise:enterpriseAll:yjlist", "person:personall:list", "integrityInformation:enterprisesGoodBehavior:list", "integrityInformation:enterprisesBadBehavior:list"}, logical=Logical.OR)
   @GetMapping("/detail/{guid}")
   public String detail(@PathVariable("guid") String guid,ModelMap mmap)
   {
	   Enterprise enterprise = enterpriseService.selectEnterpriseInfoByGuid(guid);
	   if(enterprise == null) {
		   throw new LSBusinessException("数据获取不正确，请确认选择的是否正确");
	   }
	   if(!StringUtils.isEmpty(enterprise.getFoundDate())) {
		   enterprise.setFoundDate(DateUtils.sqlServerDateTime(enterprise.getFoundDate()));
	   }
	   mmap.put("enterprise", enterprise);
	   PersonInfo legalPerson = personInfoService.selectQYPersonInfoByGuid(enterprise.getLegalPersonId());
	   mmap.put("legalPerson", legalPerson);
	   PersonInfo techPerson = personInfoService.selectQYPersonInfoByGuid(enterprise.getTechPersonId());
	   mmap.put("techPerson", techPerson);
	   PersonInfo companyLink = personInfoService.selectQYPersonInfoByGuid(enterprise.getCompanyLinkId());
	   mmap.put("companyLink", companyLink);
	   PersonInfo financeChargePerson = personInfoService.selectQYPersonInfoByGuid(enterprise.getFinanceChargePersonID());
	   mmap.put("financeChargePerson", financeChargePerson);
	   //企业资质信息
	   List<BaseCorpCertInfo> bcciList = enterpriseService.selectBaseCorpCertInfoByCompanyGuid(guid);
	   mmap.put("bcciList", bcciList);
	   mmap.put("companyGuid", guid);
	   //企业诚信评价
	   List<IGMCompanyCreditRank> igmccrList = enterpriseService.selectIGMCompanyCreditRankBycompanyGuid(guid);
	   mmap.put("igmccrList", igmccrList);
	   if(!StringUtils.isEmpty(igmccrList)) {
		   mmap.put("igmccrListOne", igmccrList.get(0));
	   }
	   return prefix + "/qiyeDetail";
   }
   
   /**
    * @Title: bulidUnitDetail
    * @Description: 建设单位详情
    * @Author wtj
    * @DateTime 2020-9-29 14:39:07
    * @param guid
    * @param mmap
    * @return
    */
   @RequiresPermissions(value={"enterprise:enterpriseAll:basicinfo", "enterprise:enterpriseAll:qua", "enterprise:enterpriseAll:cxpj", "enterprise:enterpriseAll:yjlist", "person:personall:list", "integrityInformation:enterprisesGoodBehavior:list", "integrityInformation:enterprisesBadBehavior:list"}, logical=Logical.OR)
   @GetMapping("/bulidUnitDetail/{guid}")
   public String bulidUnitDetail(@PathVariable("guid") String guid,ModelMap mmap)
   {
	   Enterprise enterprise = enterpriseService.selectEnterpriseInfoByGuid(guid);
	   if(enterprise!=null) {
		   if(!StringUtils.isEmpty(enterprise.getFoundDate())) {
			   enterprise.setFoundDate(DateUtils.sqlServerDateTime(enterprise.getFoundDate()));
		   }
		   mmap.put("enterprise", enterprise);
		   PersonInfo legalPerson = personInfoService.selectQYPersonInfoByGuid(enterprise.getLegalPersonId());
		   mmap.put("legalPerson", legalPerson);
		   PersonInfo techPerson = personInfoService.selectQYPersonInfoByGuid(enterprise.getTechPersonId());
		   mmap.put("techPerson", techPerson);
		   PersonInfo companyLink = personInfoService.selectQYPersonInfoByGuid(enterprise.getCompanyLinkId());
		   mmap.put("companyLink", companyLink);
		   PersonInfo financeChargePerson = personInfoService.selectQYPersonInfoByGuid(enterprise.getFinanceChargePersonID());
		   mmap.put("financeChargePerson", financeChargePerson);
		   //企业资质信息
		   List<BaseCorpCertInfo> bcciList = enterpriseService.selectBaseCorpCertInfoByCompanyGuid(guid);
		   mmap.put("bcciList", bcciList);
		   mmap.put("companyGuid", guid);
		   //企业诚信评价
		   List<IGMCompanyCreditRank> igmccrList = enterpriseService.selectIGMCompanyCreditRankBycompanyGuid(guid);
		   mmap.put("igmccrList", igmccrList);
		   if(!StringUtils.isEmpty(igmccrList)) {
			   mmap.put("igmccrListOne", igmccrList.get(0));
		   }
		   return prefix + "/qiyeDetail";
	   }else {
		   BaseBulidUnitInfo bbui = enterpriseService.selectBaseBulidUnitInfoByGuid(guid);
		   if(bbui == null) {
			   throw new LSBusinessException("数据获取不正确，请确认选择的是否正确");
		   }
		   mmap.put("bbui", bbui);
		   return prefix + "/bulidUnitDetail";
	   }
	   
   }
   
   /**
    * @Title: unitDetail
    * @Description: 监督站详情
    * @Author wtj
    * @DateTime 2020-9-29 14:39:18
    * @param guid
    * @param mmap
    * @return
    */
   @RequiresPermissions(value={"enterprise:enterpriseAll:basicinfo", "enterprise:enterpriseAll:qua", "enterprise:enterpriseAll:cxpj", "enterprise:enterpriseAll:yjlist", "person:personall:list", "integrityInformation:enterprisesGoodBehavior:list", "integrityInformation:enterprisesBadBehavior:list"}, logical=Logical.OR)
   @GetMapping("/unitDetail/{guid}")
   public String unitDetail(@PathVariable("guid") String guid,ModelMap mmap)
   {
	   BaseUnitInfo baseUnitInfo = new BaseUnitInfo();
	   baseUnitInfo.setGuid(guid);
	   BaseUnitInfo bui = baseUnitInfoService.selectBaseUnitInfoByGuid(baseUnitInfo);
	   mmap.put("bui", bui);
	   return prefix + "/unitDetail";
   }
   
   /**
    * @Title: detailQua
    * @Description: 显示企业资质信息数据
    * @Author wtj
    * @DateTime 2020年3月24日 下午6:11:02
    * @param guid
    * @param mmap
    * @return
    */
   @RequiresPermissions("enterprise:enterpriseAll:qua")
   @GetMapping("/detailQua/{guid}")
   public String detailQua(@PathVariable("guid") String guid,ModelMap mmap)
   {
	   List<EnterpriseTable> qualificationsList = enterpriseService.selectQualificationsByCompanyId(guid);
	   mmap.put("quaList", qualificationsList);
	   return prefix + "/qualifications";
   }
   
   /**
    * @Title: qiyeyejixinxiallList
    * @Description: 根据企业标识符查询企业业绩信息列表
    * @Author wtj
    * @DateTime 2020年4月20日 上午10:31:37
    * @param companyGuid
    * @param ip
    * @return
    */
   @RequiresPermissions("enterprise:enterpriseAll:yjlist")
   @PostMapping("/qiyeyejixinxiallList/{companyGuid}")
   @ResponseBody
   public TableDataInfo qiyeyejixinxiallList(@PathVariable("companyGuid") String companyGuid,IntegrityPerformance ip)
   {
	   startPage();
	   if(!StringUtils.isEmpty(companyGuid)) {
		   ip.setCreditCompanyInfoGuid(companyGuid);
	   }
	   List<IntegrityPerformance> ipList = enterpriseService.selectIntegrityPerformanceListByCreditCompanyInfoGuid(ip);
	   return getDataTable(ipList);
   }
   
   /**
    * @Title: qiyeyejixinxiDetail
    * @Description: 企业业绩详情
    * @Author wtj
    * @DateTime 2020-9-29 14:40:43
    * @param guid
    * @param mmap
    * @return
    */
   @RequiresPermissions("enterprise:enterpriseAll:yjdetail")
   @GetMapping("/qiyeyejixinxiDetail/{guid}")
   public String qiyeyejixinxiDetail(@PathVariable("guid") String guid,ModelMap mmap)
   {
	   IntegrityPerformance ip = enterpriseService.selectIntegrityPerformanceByGuid(guid);
	   mmap.put("ip", ip);
	   if(ip.getCorpCertType().trim().equals("检测机构资质")) {
		   return prefix + "/qiyejiance";
	   }
	   return prefix + "/zaiqiongyeji";
   }
   
   /**
    * @Title: qiyerenyuanallList
    * @Description: 企业人员列表获取数据
    * @Author wtj
    * @DateTime 2020-9-29 14:40:55
    * @param companyGuid
    * @param personInfo
    * @return
    */
   @RequiresPermissions("person:personall:list")
   @PostMapping("/qiyerenyuanallList/{companyGuid}")
   @ResponseBody
   public TableDataInfo qiyerenyuanallList(@PathVariable("companyGuid") String companyGuid,PersonInfo personInfo)
   {
	   startPage();
	   if(!StringUtils.isEmpty(companyGuid)) {
		   personInfo.setCompanyGuid(companyGuid);
	   }
	   List<PersonInfo> piList = personInfoService.selectBasePersonInfoByCompanyGuid(personInfo);
	   return getDataTable(piList);
   }
   
   /**
    * @Title: qiyelianghaoList
    * @Description: 企业良好行为行为获取列表数据
    * @Author wtj
    * @DateTime 2020-9-29 14:41:08
    * @param companyGuid
    * @param igmcwi
    * @return
    */
   @RequiresPermissions("integrityInformation:enterprisesGoodBehavior:list")
   @PostMapping("/qiyelianghaoList/{companyGuid}")
   @ResponseBody
   public TableDataInfo qiyelianghaoList(@PathVariable("companyGuid") String companyGuid,IGMCompanyWellInfo igmcwi)
   {
	   startPage();
	   if(!StringUtils.isEmpty(companyGuid)) {
		   igmcwi.setCompanyGuid(companyGuid);
	   }
	   List<IGMCompanyWellInfo> igmcwiList = enterpriseService.selectIGMCompanyWellInfoListByCompanyGuid(igmcwi);
	   return getDataTable(igmcwiList);
   }
   
   /**
    * @Title: qiyelianghaoDetail
    * @Description: 企业良好行为详情
    * @Author wtj
    * @DateTime 2020-9-29 14:42:11
    * @param guid
    * @param mmap
    * @return
    */
   @RequiresPermissions("integrityInformation:enterprisesGoodBehavior:detail")
   @GetMapping("/qiyelianghaoDetail/{guid}")
   public String qiyelianghaoDetail(@PathVariable("guid") String guid,ModelMap mmap)
   {
	   IGMCompanyWellInfo igmcwi = enterpriseService.selectIGMCompanyWellInfoByGuid(guid);
	   mmap.put("igmcwi", igmcwi);
	   return prefix + "/qiyelianghaoxinxi";
   }
   
   /**
    * @Title: qiyelianghaoList
    * @Description: 企业不良行为获取列表数据
    * @Author wtj
    * @DateTime 2020-9-29 14:42:46
    * @param companyGuid
    * @param igmcpi
    * @return
    */
   @RequiresPermissions("integrityInformation:enterprisesBadBehavior:list")
   @PostMapping("/qiyebuliangList/{companyGuid}")
   @ResponseBody
   public TableDataInfo qiyelianghaoList(@PathVariable("companyGuid") String companyGuid,IGMCompanyPoorInfo igmcpi)
   {
	   startPage();
	   if(!StringUtils.isEmpty(companyGuid)) {
		   igmcpi.setCompanyGuid(companyGuid);
	   }
	   List<IGMCompanyPoorInfo> igmcpiList = enterpriseService.selectIGMCompanyPoorInfoListByCompanyGuid(igmcpi);
	   return getDataTable(igmcpiList);
   }
   
   /**
    * @Title: qiyebuliangDetail
    * @Description: 企业不良行为详情
    * @Author wtj
    * @DateTime 2020-9-29 14:43:00
    * @param guid
    * @param mmap
    * @return
    */
   @RequiresPermissions("integrityInformation:enterprisesBadBehavior:detail")
   @GetMapping("/qiyebuliangDetail/{guid}")
   public String qiyebuliangDetail(@PathVariable("guid") String guid,ModelMap mmap)
   {
	   IGMCompanyPoorInfo igmcpi = enterpriseService.selectIGMCompanyPoorInfoByGuid(guid);
	   mmap.put("igmcpi", igmcpi);
	   return prefix + "/qiyebuliangxinxi";
   }
   
   @GetMapping("/test")
   public String qiyeyejixinxiDetail()
   {
	   List<MyTest> testList = myTestService.selectMyTest();
	   return null;
   }
}
